#include "sessionconfig.h"

#include "config.h"
using namespace stitch;


SessionConfig::SessionConfig(Config *p_mgr)
:IConfig(p_mgr,nullptr)
{

}

SessionConfig::~SessionConfig()
{

}

void SessionConfig::init()
{
    auto mgr = getMgr();
    auto sessionSettings = mgr->getSettings(Config::Source::Session);

    const auto &sessionJobj = sessionSettings->getJson();

}

void SessionConfig::writeToSettings() const
{
        getMgr()->writeSessionSettings(toJson());
}

QJsonObject SessionConfig::toJson() const
{
    QJsonObject obj;
//    obj[QStringLiteral("core")] = saveCore();
//    obj[QStringLiteral("notebooks")] = saveNotebooks();
//    obj[QStringLiteral("state_geometry")] = saveStateAndGeometry();
//    obj[QStringLiteral("export")] = saveExportOption();
//    obj[QStringLiteral("search_option")] = m_searchOption.toJson();
//    writeByteArray(obj, QStringLiteral("viewarea_session"), m_viewAreaSession);
//    writeByteArray(obj, QStringLiteral("notebook_explorer_session"), m_notebookExplorerSession);
//    obj[QStringLiteral("external_programs")] = saveExternalPrograms();
//    obj[QStringLiteral("history")] = saveHistory();
    return obj;
}

///false 表示有
bool SessionConfig::getSystemTitleBarEnabled() const
{
    return m_systemTitleBarEnabled;
}

void SessionConfig::setSystemTitleBarEnabled(bool p_enabled)
{
    updateConfig(m_systemTitleBarEnabled, p_enabled, this);
}

const QString &SessionConfig::getFlashPage() const
{
    return m_flashPage;
}

void SessionConfig::setFlashPage(const QString &p_file)
{
    updateConfig(m_flashPage, p_file, this);
}

const QStringList &SessionConfig::getQuickAccessFiles() const
{
    return m_quickAccessFiles;
}

void SessionConfig::setQuickAccessFiles(const QStringList &p_files)
{
    QStringList files;
    for (const auto &file : p_files) {
        auto fi = file.trimmed();
        if (!fi.isEmpty()) {
            files << fi;
        }
    }
    updateConfig(m_quickAccessFiles, files, this);
}

void SessionConfig::removeQuickAccessFile(const QString &p_file)
{
    if (m_quickAccessFiles.removeOne(p_file)) {
        update();
    }
}
